/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.webautomationmodule.services;

import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleActionFactory;
import org.testis.testdriver.AtofEnumaration.AtofWebAutomationModuleAction;


/**
 * A factory class to created web automation module action objects
 * @author nurhat
 */
public class WebAutomationModuleActionFactory extends AtofModuleActionFactory
{

    /**
     * Creates an action object according to given action type
     * @param actionType
     * @return
     */
    @Override
    public AtofModuleAction getActionObject(String actionType)
    {
        AtofWebAutomationModuleAction action;
        try {
            action = AtofWebAutomationModuleAction.valueOf(actionType);
        } catch (IllegalArgumentException ex) {

            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "Action type given " + actionType +
                                        " not found for Web Automation Application ..." +
                                        ex.getMessage());
        }

        AtofModuleAction actionObj = null, actionObj2;
        if (action == AtofWebAutomationModuleAction.GetAndVerify) {
            actionObj = new VerifyAction();

        }
        else if (action == AtofWebAutomationModuleAction.Set) {
            actionObj = new SetAction();
        }
        else if (action == AtofWebAutomationModuleAction.SetAndVerify) {
            actionObj = new SetAction();
            actionObj2 = new VerifyAction();
            actionObj.setSuccessor(actionObj2);
        }
        else if (action == AtofWebAutomationModuleAction.Get) {
            actionObj = new GetAction();
        }
        else {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "Action type given " + actionType +
                                        " not found for Web Automation ...");
        }
        return actionObj;
    }
}
